package com.onefish.toolkit.natives.custom;

import com.onefish.toolkit.natives.support.AbstractNativeLibraryLoader;
import com.onefish.toolkit.natives.support.CustomNativeEnum;
import com.sun.jna.Library;

/**
 * 三方业务处理器
 *
 * @author onefish
 */
public class CustomHandler extends AbstractNativeLibraryLoader<Library> {
    private static final CustomHandler INSTANCE = new CustomHandler();

    public CustomHandler() {
        //  拒绝反射方式创建实例，保证单例完整性
        if (INSTANCE != null) throw new IllegalStateException("CustomHandler already initialized");
        super.generateTemplateStruct();
    }

    public static CustomHandler getInstance() {
        return INSTANCE;
    }

    /**
     * 定制算法逻辑
     *
     * @param a 形参1
     * @param b 形参2
     * @return 5倍加和
     */
    public static int customAdd(int a, int b) {
        CustomHandler customHandler = getInstance();
        String libPath = customHandler.getLibPath();
        CustomLibrary customLibrary = customHandler.load(libPath, CustomLibrary.class);
        return 5 * customLibrary.add(a, b);
    }

    public CustomNativeEnum getNativeEnum() {
        return CustomNativeEnum.ONE_FISH;
    }

    @Override
    protected CustomNativeEnum setTripartite() {
        return getNativeEnum();
    }
}
